package main

import (
	"os"

	"github.com/urfave/cli/v2"
)

func main() {

	// 创建配置
	config := NewConfig()

	// 配置命令行
	app := &cli.App{
		Version: "0.0.1",
		Commands: []*cli.Command{
			{
				Name: "run",
				Action: func(c *cli.Context) error {
					config.File = c.Args().First()
					RunFile(config)
					return nil
				},
			},
			{
				Name: "format",
				Flags: []cli.Flag{
					&cli.StringFlag{
						Name:    "output",
						Aliases: []string{"o"},
						Usage:   "Output the formatted `FILE`",
					},
					&cli.IntFlag{
						Name:    "tab",
						Aliases: []string{"t"},
						Value:   4,
						Usage:   "The tab length of the formatted code",
					},
				},
				Action: func(c *cli.Context) error {
					config.File = c.Args().First()
					FormatFile(config, &FormatOption{
						file: c.String("output"),
						tab:  c.Int("tab"),
					})
					return nil
				},
			},
		},
		Action: func(c *cli.Context) error {
			return nil
		},
	}

	// 运行主程序
	app.Run(os.Args)
}
